﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using Microsoft.Reporting.WinForms;
/*using Iprojects.DataLayer;*/
using Iprojects.Data;
using System.Linq;
using System.Data.Objects;
using Iprojects.Report;
/*using DbLinq;
using DbLinq.Sqlite;*/
/*using Iprojects.Data;*/
namespace Iprojects.Forms
{
    public partial class ReportMasrofatByDateAndProject : Form
    {
        DataSet ReportData =new DataSet();
        DataTable ReportDatatable = new DataTable();
        DataTable dt = createDataTableProjectMoslemFamily();
        
       
        int familyid = 0;
        public ReportMasrofatByDateAndProject()
        {
            InitializeComponent();
            dateFrom.Value = DateTime.Now.AddYears(-1);
            dateFrom.Format = DateTimePickerFormat.Custom;
            dateFrom.CustomFormat = "dd/mm/yyyy";

            dateTo.Value = DateTime.Now;
            dateTo.Format = DateTimePickerFormat.Custom;
            dateTo.CustomFormat = "dd/mm/yyyy";
          

    
        //    dtGridFamilyProjectHistory.AutoGenerateColumns = false;

         //   dtGridFamilyProjectHistory.Columns.Add("sum", "مجموع  ");
          

            
           
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
         //   PersonsInProjects _personinPrj = new PersonsInProjects();
           
            switch (comboBox1.SelectedIndex )
            {/*
          
مشروع الاسرة المسلمة
مشروع الحقائب المدرسية
مشروع الطرود الغذائة
مشروع ترميم البيوت
              */               
                case 0:
                    RenderReport(new moslemFamilyProject() );
                    break;
                case 1 :
                    RenderReport(new SchoolBagsProject());
                    break;
                case 2:
                    RenderReport(new FoodBoxProject());
                    break;
                case 3:
                    RenderReport(new HomeFixesProject());
                    break;
                default:
                    break;
            }


        
            




      
      
    
        }

        private void RenderReport(HomeFixesProject homeFixesProject)
        {
            List<PersonsInProjects> allFamiliesinProj = new List<PersonsInProjects>();
            ZakahEntities db = new ZakahEntities();
           
            var query = from p in db.HomeFixesProjects.Where(x => (x.date >= dateFrom.Value) && (x.date <= dateTo.Value))
                        select p;
            string MasrofSummary = string.Empty;
            long? sum = query.Sum(x => x.amount);
            MasrofSummary = "   المبلغ الذي وزع بين هذه التواريخ : " + sum.ToString() +"\n";
           
          
          
            List<HomeFixesProject> allprj = query.ToList<HomeFixesProject>();
            foreach (HomeFixesProject item in allprj)
            {
                PersonsInProjects _personinproject = new PersonsInProjects(item.familyID);
                _personinproject.date = Convert.ToDateTime(item.date).ToString("M/d/yyyy");
                _personinproject.Amount = item.amount ;
                          _personinproject.Titleamount = "مبلغ الترميم";
                 _personinproject.AdditionalData+= "عدد الغرف :"+ item.RoomNumbers +"\n";
                 _personinproject.AdditionalData += " احتياجات الترميم :" + item.Tarmimdemands + "\n";
                 _personinproject.AdditionalData += "  تكاليف الترميم :" + item.TarmimTakalef + "\n";
                 _personinproject.AdditionalData += "   ملاحظات :" + item.Note + "\n";
                // _personinproject.ProjectName = comboBox1.Text;
                allFamiliesinProj.Add(_personinproject);
            }


            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet_PersoninFamily", allFamiliesinProj));
            ReportParameter p1 = new ReportParameter("DateFrom", dateFrom.Value.ToString("mm/dd/yyyy"));
            ReportParameter p2 = new ReportParameter("DateTo", dateTo.Value.ToString("mm/dd/yyyy"));
            ReportParameter p3 = new ReportParameter("project", comboBox1.Text);
            ReportParameter p4 = new ReportParameter("MasrofSummary", MasrofSummary);
            
            reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3,p4 });
            reportViewer1.Visible = true;
            this.reportViewer1.RefreshReport(); 
        }

        private void RenderReport(FoodBoxProject foodBoxProject)
        {
            List<PersonsInProjects> allFamiliesinProj = new List<PersonsInProjects>();
            ZakahEntities db = new ZakahEntities();
            var query = from p in db.FoodBoxProjects.Where(x => (x.date >= dateFrom.Value) && (x.date <= dateTo.Value))
                        select p;
            string MasrofSummary = string.Empty;
            long? sum = query.Sum(x => x.amount);
            MasrofSummary = "   عدد الطرود التي وزعت بين هذه التواريخ : " + sum.ToString() + "\n";
           
          
            List<FoodBoxProject> allprj = query.ToList<FoodBoxProject>();
            foreach (FoodBoxProject item in allprj)
            {
                PersonsInProjects _personinproject = new PersonsInProjects(item.familyID);
                _personinproject.date = Convert.ToDateTime(item.date).ToString("M/d/yyyy");
                _personinproject.Amount = item.amount;
                _personinproject.Titleamount = "عدد الطرود";
                // _personinproject.ProjectName = comboBox1.Text;
                allFamiliesinProj.Add(_personinproject);
            }


            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet_PersoninFamily", allFamiliesinProj));
            ReportParameter p1 = new ReportParameter("DateFrom", dateFrom.Value.ToString("mm/dd/yyyy"));
            ReportParameter p2 = new ReportParameter("DateTo", dateTo.Value.ToString("mm/dd/yyyy"));
            ReportParameter p3 = new ReportParameter("project", comboBox1.Text);
            ReportParameter p4 = new ReportParameter("MasrofSummary", MasrofSummary);
            
            reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3,p4 });
            reportViewer1.Visible = true;
            this.reportViewer1.RefreshReport(); 
        }

        private void RenderReport(SchoolBagsProject schoolBagsProject)
        {


            List<PersonsInProjects> allFamiliesinProj = new List<PersonsInProjects>();
            ZakahEntities db = new ZakahEntities();
            var query = from p in db.SchoolBagsProjects.Where(x => (x.date >= dateFrom.Value) && (x.date <= dateTo.Value))
                        select p;
            string MasrofSummary = string.Empty;
            long? sum = query.Sum(x => x.amount);
            MasrofSummary = "عدد الحقائب التي وزعت بين هذه التواريخ : " + sum.ToString();

            List<SchoolBagsProject> allprj = query.ToList<SchoolBagsProject>();
            foreach (SchoolBagsProject item in allprj)
            {
                PersonsInProjects _personinproject = new PersonsInProjects(item.familyID);
                _personinproject.date = Convert.ToDateTime(item.date).ToString("M/d/yyyy");
                _personinproject.Amount = item.amount;
                _personinproject.Titleamount = "عدد الحقائب";
                // _personinproject.ProjectName = comboBox1.Text;
                allFamiliesinProj.Add(_personinproject);
            }


            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet_PersoninFamily", allFamiliesinProj));
            ReportParameter p1 = new ReportParameter("DateFrom", dateFrom.Value.ToString("mm/dd/yyyy"));
            ReportParameter p2 = new ReportParameter("DateTo", dateTo.Value.ToString("mm/dd/yyyy"));
            ReportParameter p3 = new ReportParameter("project", comboBox1.Text);
            ReportParameter p4 = new ReportParameter("MasrofSummary", MasrofSummary);
            
            reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3,p4 });
            reportViewer1.Visible = true;
            this.reportViewer1.RefreshReport(); 
        }

        private void RenderReport(moslemFamilyProject moslemFamilyProject)
        {
            List<PersonsInProjects> allFamiliesinProj=new List<PersonsInProjects>();
            ZakahEntities db = new ZakahEntities();
            var query  = from p in db.moslemFamilyProjects.Where(x => (x.date >= dateFrom.Value) && (x.date <= dateTo.Value))
                         select p;

            string MasrofSummary = string.Empty;
            long? sum = query.Sum(x => x.amount);
            MasrofSummary = "  المبلغ الذي وزع بين هذه التواريخ : " + sum.ToString() + "\n";
           
               List<moslemFamilyProject> allprj = query.ToList<moslemFamilyProject>();
               foreach (moslemFamilyProject item in allprj)
               {
                   PersonsInProjects _personinproject = new PersonsInProjects(item.familyID);
                   _personinproject.date = Convert.ToDateTime(item.date).ToString("M/d/yyyy");

                   _personinproject.Amount = item.amount;
                   _personinproject.Titleamount = "المبلغ";
                  // _personinproject.ProjectName = comboBox1.Text;
                   allFamiliesinProj.Add(_personinproject);
               }


               this.reportViewer1.LocalReport.DataSources.Clear();
               this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet_PersoninFamily", allFamiliesinProj));
               ReportParameter p1 = new ReportParameter("DateFrom", dateFrom.Value.ToString("mm/dd/yyyy"));
               ReportParameter p2 = new ReportParameter("DateTo", dateTo.Value.ToString("mm/dd/yyyy"));
               ReportParameter p3 = new ReportParameter("project", comboBox1.Text);
               ReportParameter p4 = new ReportParameter("MasrofSummary", MasrofSummary);
            
               reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3,p4 });
               reportViewer1.Visible = true;
               this.reportViewer1.RefreshReport();  
          
            
        }
        /// <summary>
        /// Render Report of selected PRoject
        /// </summary>
        /// <param name="p"></param>
        private void RenderReport()
        {
          
        }

          

           private void ReportByDateAndProject_Load(object sender, EventArgs e)
           {

               this.reportViewer1.RefreshReport();
           }
           public static  DataTable createDataTableProjectMoslemFamily()
           {
               //
               // Here we create a DataTable with four columns.
               //
               DataTable table = new DataTable();
               table.Columns.Add("Dosage", typeof(int));
               table.Columns.Add("Drug", typeof(string));
               table.Columns.Add("Patient", typeof(string));
               table.Columns.Add("Date", typeof(DateTime));

               //
               // Here we add five DataRows.
               //
               table.Rows.Add(25, "Indocin", "David", DateTime.Now);
               table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
               table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
               table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
               table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
               return table;
           }

           private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
           {
               btnAddFamily.Enabled = true;
           }

        }

   
    }



